#define _CRT_SECURE_NO_WARNINGS 1

void Slectsort(int* a, int len)
{
	
	for (int i = 0;i < len - 1;i++)
	{
		int end = i;
		int tmp = a[end + 1];
		while (end >= 0)
		{
			if (a[end] > tmp)
			{
				a[end + 1] = a[end];
				end--;
			}
			else
			{
				break;
			}
		}
		a[end + 1] = tmp;
	}
}

void Sellsort(int* a, int len)
{
	int gap = len;
	while (gap > 1)
	{
		gap = (gap / 3 + 1);
		for (int i = 0;i < len - gap;++i)
		{
			int end = i;
			int tmp = a[end + gap];
			while (end >= 0)
			{
				if (a[end] < tmp)
				{
					a[end + gap] = a[end];
					end -= gap;
				}
				else
				{
					break;
				}
			}
			a[end + gap] = tmp;
		}
	}

}
void swap(int* m, int* n)
{
	int tmp = *m;
	*m = *n;
	*n = tmp;
}
void Select(int* a, int len)
{
	int left = 0, right = len - 1;
	
	while (left < right)
	{
		int Indexmin = left, Indexmax = left;
		for (int i = left;i <= right;++i)
		{
			if (a[i] > a[Indexmax])
				Indexmax = i;

			if (a[i] < a[Indexmin])
				Indexmin = i;
		}
		swap(&a[left], &a[Indexmin]);
		if (left == Indexmax)
		{
			Indexmax = Indexmin;
		}
		swap(&a[right], &a[Indexmax]);
		--right;
		++left;
	}
}
int main()
{
	int arr[] = { 10,9,8,7,0,-1,-2 };
	int len = sizeof(arr) / sizeof(arr[0]);
	//Sellsort(arr, len);
	//Slectsort(arr, len);
	Select(arr, len);


	
	return 0;
}